$(function () {
    /*
     * 在学生列表展示更多操作
     */
    $(".student_more").on("click", function () {
        $(this).next().animate({
            width: "90px",
            right: "10px"
        }, 300);
    })

    $(".student_list tbody tr").on("mouseleave", function () {
        $(".student_btn").animate({
            width: "0px",
            right: "0"
        }, 200)
    })

    /*
     * 删除学生
     */
    $(".student_delete").on("click", function () {
        var _s = $(this);
        crm.alert("是否要删除?", "warning", function () {
            var now_student = _s.parent().parent().parent().parent().parent().attr("data-id");
            var data = {
                "id": now_student
            };
            var request_url = package_url("administration_module/index/delete");
            var order_url = package_url("administration_module/index/show_list");
            var callback = function (res) {
                if (res.status == 1) {
                    crm.alert(res.msg, "success", function () {
                        location.href = order_url;
                    });
                } else {
                    crm.alert(res.msg, "error", function () {
                        location.href = order_url;
                    });
                }
            };
            crm_ajax(data, request_url, callback);
        }, true);
    })

    /*
     * 恢复咨询者
     */
    $(".student_restore").on("click", function () {
        var _s = $(this);
        crm.alert("是否要恢复?", "warning", function () {
            var now_student = _s.parent().parent().attr("data-id");
            var data = {
                "id": now_student
            };
            var request_url = package_url("administration_module/index/confirm_restore");
            var order_url = package_url("administration_module/index/show_restore");
            var callback = function (res) {
                if (res.status == 1) {
                    crm.alert(res.msg, "success", function () {
                        location.href = order_url;
                    });
                } else {
                    crm.alert(res.msg, "error", function () {
                        location.href = order_url;
                    });
                }
            };
            crm_ajax(data, request_url, callback);
        }, true);
    })
    /*
     * 学生详情信息展示
     */
    $(".student_show").on("click", function () {
        var now_student_id = $(this).parent().parent().attr("data-id");
        var data = {
            "now_student": now_student_id
        }
        var request_url = package_url("administration_module/index/get_stu_info");
        crm_ajax(data, request_url, function (res) {
            var popup_html = `<div class='row wrapper info_content'><div class='col-sm-3 info_left'>姓名</div><div class='col-sm-9 info_right'>${res[0].name}</div><div class='col-sm-3 info_left'>电话号码</div><div class='col-sm-9 info_right'>${res[0].phone}</div><div class='col-sm-3 info_left'>学校</div><div class='col-sm-9 info_right'>${res[0].school ? res[0].school : 'NULL'}</div><div class='col-sm-3 info_left'>所读专业</div><div class='col-sm-9 info_right'>${res[0].major ? res[0].major : 'NULL'}</div><div class='col-sm-3 info_left'>所属班级</div><div class='col-sm-9 info_right'>${res[0].class_name ? res[0].class_name : 'NULL'}</div><div class='col-sm-3 info_left'>咨询师</div><div class='col-sm-9 info_right'>${res[0].staff_name ? res[0].staff_name : 'NULL'}</div><div class='col-sm-3 info_left'>身份证号码</div><div class='col-sm-9 info_right'>${res[0].id_card ? res[0].id_card : 'NULL'}</div><div class='col-sm-3 info_left'>电脑情况</div><div class='col-sm-9 info_right'>${res[0].is_computer ? res[0].is_computer : 'NULL'}</div><div class='col-sm-3 info_left'>状态</div><div class='col-sm-9 info_right'>${res[0].type ? res[0].type : 'NULL'}</div><div class='col-sm-3 info_left'>咨询师评价</div><div class='col-sm-9 info_right'>${res[0].evaluation ? res[0].evaluation : 'NULL'}</div></div><div class='popup_bottom'><a href='/administration_module/index/show_edit/now_student/${res[0].id}/now_name/${res[0].name}' class='btn btn-s-md btn-default'>修 改</a></div>`;
            popup_window(res[0].name, popup_html);
        })
    })
    /*
     * 学生学习记录弹窗
     */
    $(".student_record").on("click", function () {
        var now_student = $(this).parent().parent().parent().parent().parent().attr("data-id");
        var now_name = $(this).parent().parent().parent().parent().parent().attr("data-name");
        var data = {
            "now_consultant": now_student
        };
        var request_url = package_url("administration_module/index/study_record");
        study_record(data, request_url, now_name, now_student);
    })

    /*
     * 展示学生记录弹窗
     */
    function study_record(data, request_url, now_name, now_student) {
        crm_ajax(data, request_url, function (res) {
            console.log(res);
        })
    }
})